package com.gitee.wsl.jvm.ext.base

import java.util.concurrent.atomic.AtomicInteger

/**
 *  Increases an AtomicInteger safely.
 */
fun AtomicInteger.getAndIncrementNoOverflow() {
    var prev: Int
    var next: Int
    do {
        prev = this.get()
        next = if (prev == Integer.MAX_VALUE) prev else prev + 1
    } while (!this.compareAndSet(prev, next))
}